import 'package:flutter/cupertino.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:practice_app/router/app_pages.dart';
import 'package:practice_app/service/global.dart';

import 'I18next/translations.dart';
Future<void> main() async {
  await initServices();
  runApp(MyApp());
}

Future<void> initServices() async {
  print('starting services ...');
  await Get.putAsync(() => GlobalConfigService().init());
  print('All services started...');
}
class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: (){
        //点击其他地方，收起键盘
        hideKeyboard(context);
      },
      child: ScreenUtilInit( //设置ui设计标准尺寸
        designSize: const Size(375, 667),
        minTextAdapt: true,
        splitScreenMode: true,
        builder: (_,child) => GetMaterialApp(
          builder:  EasyLoading.init(),//全局加载状态
          translations: Message(),//翻译库
          defaultTransition: Transition.fadeIn,//页面切换动画
          locale: Get.deviceLocale,// 国家化跟随系统
          fallbackLocale: const Locale('zh', 'CN'),//如果没有相应的语言库就默认中文
          debugShowCheckedModeBanner: false,
          initialRoute: AppPages.INITIAL,//初始化路由
          getPages: AppPages.routes,//初始化页面

        ),
      ),
    );
  }
  /// 隐藏键盘
  void hideKeyboard(BuildContext context) {
    FocusScopeNode currentFocus = FocusScope.of(context);
    if (!currentFocus.hasPrimaryFocus && currentFocus.focusedChild != null) {
      FocusManager.instance.primaryFocus?.unfocus();
    }
  }
}
